<template>
  <section>
    <!--工具条-->
    <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
      <el-form :inline="true" :model="filters">
        <el-form-item>
          <el-input v-model="filters.keyword" placeholder="关键字"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" v-on:click="search">查询</el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="handleAdd">新增</el-button>
        </el-form-item>
      </el-form>
    </el-col>

    <!--列表-->
    <el-table @row-dblclick="test" :data="Systemdetailtionarydetails" highlight-current-row v-loading="listLoading" @selection-change="selsChange" style="width: 100%;">
      <el-table-column type="selection" width="55">
      </el-table-column>
      <el-table-column type="index" width="60">
      </el-table-column>
      <el-table-column prop="name" label="字典明细" width="120" >
      </el-table-column>
      <el-table-column prop="type.name" label="字典类型" width="120" >
      </el-table-column>
      <el-table-column label="操作" width="150">
        <template scope="scope">
          <el-button size="small" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
          <el-button type="danger" size="small" @click="handleDel(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

<!--    <el-drawer-->
<!--      title="数据字典明细类型"-->
<!--      :visible.sync="table"-->
<!--      direction="rtl"-->
<!--      size="50%">-->
<!--      <el-table :data="gridData">-->
<!--        <el-table-column property="id" label="编号" width="150"></el-table-column>-->
<!--        &lt;!&ndash;          <el-input v-model="editForm.managerId" auto-complete="off"></el-input>&ndash;&gt;-->
<!--        <el-select v-model="editForm.id" placeholder="请选择">-->
<!--          <el-option-->
<!--            v-for="item in Systemdictionarydetail"-->
<!--            :label="item.name"-->
<!--            :value="item.id">-->
<!--            <span style="float: left">{{ item.name }}</span>-->
<!--            <span style="float: right; color: #8492a6; font-size: 13px">{{item.typesId}}</span>-->
<!--          </el-option>-->
<!--        </el-select>-->
<!--      </el-table>-->
<!--    </el-drawer>-->

    <!--工具条-->
    <el-col :span="24" class="toolbar">
      <el-button type="danger" @click="batchRemove" :disabled="this.sels.length===0">批量删除</el-button>
      <el-pagination layout="prev, pager, next" @current-change="handleCurrentChange"
                     :total="totals" style="float:right;"
                     :current-page="currentPage"  :page-size="pageSize">
      </el-pagination>
    </el-col>

    <!--编辑界面-->
    <el-dialog :title="title" :visible.sync="editFormVisible" :close-on-click-modal="false">
      <el-form :model="editForm" label-width="80px" :rules="editFormRules" ref="editForm">
        <el-form-item label="字典明细" prop="name">
          <el-input v-model="editForm.name" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="字典类型" prop="name">
          <el-select v-model="editForm.typesId" placeholder="请选择">
            <el-option
              v-for="item in lowthings"
              :label="item.name"
              :value="item.id">
              <span style="float: left">{{ item.name }}</span>
              <span style="float: right; color: #8492a6; font-size: 13px">{{ item.id }}</span>
            </el-option>
          </el-select>
        </el-form-item>
<!--        <el-form-item label="字典明细" prop="name">-->
<!--&lt;!&ndash;          <el-input v-model="editForm.managerId" auto-complete="off"></el-input>&ndash;&gt;-->
<!--          <el-select v-model="editForm.id" placeholder="请选择">-->
<!--            <el-option-->
<!--              v-for="item in Systemdetailtionarydetail"-->
<!--              :label="item.name"-->
<!--              :value="item.id">-->
<!--              <span style="float: left">{{ item.name }}</span>-->
<!--              <span style="float: right; color: #8492a6; font-size: 13px">{{item.typesId}}</span>-->
<!--            </el-option>-->
<!--          </el-select>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="上级部门" prop="name">-->
<!--          <el-input v-model="editForm.parentId" auto-complete="off"></el-input>-->
<!--          <div class="block">-->
<!--            <span class="demonstration"></span>-->
<!--            <el-cascader-->
<!--              v-model="editForm.parentId"-->
<!--              :options="options"-->
<!--              :props="{ checkStrictly: true,-->
<!--               value:'id',-->
<!--               label:'name'-->
<!--               }"-->
<!--              clearable></el-cascader>-->
<!--          </div>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="权限">-->
<!--          <el-radio-group v-model="editForm.state">-->
<!--            <el-radio class="radio" :label="1">启用</el-radio>-->
<!--            <el-radio class="radio" :label="0">禁用</el-radio>-->
<!--          </el-radio-group>-->
<!--        </el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click.native="editFormVisible = false">取消</el-button>
        <el-button type="primary" @click.native="editSubmit" :loading="editLoading">提交</el-button>
      </div>
    </el-dialog>
  </section>
</template>

<script>
import util from '../../common/js/util'
//import NProgress from 'nprogress'
// import { getDepartmentListPage, removeDepartment, batchRemoveDepartment, editDepartment, addDepartment } from '../../api/api';

export default {
  data() {
    return {
      lowthings:[],
      options:[],
      employees:[],
      title:'',
      filters: {
        keyword: ''
      },
      Systemdetailtionarydetails:[],
      gridData:[],
      table:false,
      totals: 0,
      // page: 1,
      pageSize: 5,
      currentPage: 1,
      listLoading: false,
      sels: [],//列表选中列

      editFormVisible: false,//编辑界面是否显示
      editLoading: false,
      editFormRules: {
        name: [
          { required: true, message: '请输入姓名', trigger: 'blur' }
        ]
      },
      //编辑界面数据
      editForm: {
      },
      //
      // addFormVisible: false,//新增界面是否显示
      // addLoading: false,
      // addFormRules: {
      //   name: [
      //     { required: true, message: '请输入姓名', trigger: 'blur' }
      //   ]
      // },
      //新增界面数据
      // addForm: {
      //   name: '',
      //   sex: -1,
      //   age: 0,
      //   birth: '',
      //   addr: ''
      // }

    }
  },
  methods: {
    //获取明细类型选择下拉
    getType(){
      this.$http.post("/dic/low")
        .then(Result=>{
          this.lowthings = Result.data;
          console.log(Result.data)

        }).catch(Result=>{

      })
    },
    search(){
      this.currentPage=1
      this.getSystemdictionarydetails()

    },


    handleCurrentChange(val) {
      this.currentPage = val;
      this.getSystemdictionarydetails();
    },




    //获取字典列表
    getSystemdictionarydetails() {
      console.log(this.pageSize)
      let para = {
        pageSize: this.pageSize,
        currentPage: this.currentPage,
        keyword: this.filters.keyword

      };
      this.listLoading = true;
      this.$http.post("/detail", para)
          .then(result=>{
            this.listLoading = false;
            this.Systemdetailtionarydetails = result.data.rows;
            this.totals = result.data.totals;
          })
          .catch(result=>{
            console.log(this.pageSize);
            console.log(this.currentPage);
            this.$message({
              message: '网络走丢了',
              type: 'error'
            });
          })
      //NProgress.start();
      // getDepartmentListPage(para).then((res) => {
      // 	this.totals = res.data.totals;
      // 	this.Systemdetailtionarydetails = res.data.Systemdetailtionarydetails;
      // 	this.listLoading = false;
      // 	//NProgress.done();
      // });
    },
    //删除
    handleDel: function (index, row) {
      this.$confirm('确认删除该记录吗?', '提示', {
        type: 'warning'
      }).then(() => {
        this.listLoading = true;
        //NProgress.start();
        let para = { id: row.id };
        this.$http.delete("/detail/"+row.id)
        .then(Result=>{
          this.listLoading = false;
          this.getSystemdictionarydetails();
          if (Result.data.success){
            this.$message({
              message: Result.data.msg,
              type: 'success'
            })
          }
        })
        .catch(Result=>{
          this.$message({
            message: '网络走丢了',
            type: 'error'
          });
        })
      }).catch(() => {
      });
    },
    //显示编辑界面
    handleEdit: function (index, row) {
      this.editFormVisible = true;
      this.title='编辑';
      this.editForm = Object.assign({}, row);
    },
    //显示新增界面
    handleAdd: function () {
      this.editFormVisible = true;
      this.title='新增';
      this.editForm = {};
    },
    //编辑
    editSubmit: function () {
      this.$refs.editForm.validate((valid) => {
        if (valid) {
          this.$confirm('确认提交吗？', '提示', {}).then(() => {
            this.editLoading = true;
            //NProgress.start();
            let para = Object.assign({}, this.editForm);
           this.$http.put("/detail",para).then(Result => {
              this.editLoading = false;
              this.editFormVisible=false
             if (Result.data.success){
               this.$message({
                 message: Result.data.msg,
                 type: 'success'
               })
             }
              this.$refs['editForm'].resetFields();
              this.editFormVisible = false;
              this.getSystemdictionarydetails();
            })
            .catch(Result=>{
              this.$message({
                message: '网络走丢了',
                type: 'error'
              });

            })
          });
        }
      });
    },
    //新增
    // addSubmit: function () {
    //   this.$refs.addForm.validate((valid) => {
    //     if (valid) {
    //       this.$confirm('确认提交吗？', '提示', {}).then(() => {
    //         this.addLoading = true;
    //         //NProgress.start();
    //         let para = Object.assign({}, this.addForm);
    //         para.birth = (!para.birth || para.birth == '') ? '' : util.formatDate.format(new Date(para.birth), 'yyyy-MM-dd');
    //         addDepartment(para).then((res) => {
    //           this.addLoading = false;
    //           //NProgress.done();
    //           this.$message({
    //             message: '提交成功',
    //             type: 'success'
    //           });
    //           this.$refs['addForm'].resetFields();
    //           this.addFormVisible = false;
    //           this.getSystemdictionarydetails();
    //         });
    //       });
    //     }
    //   });
    // },
    selsChange: function (sels) {
      this.sels = sels;
    },
    //批量删除
    batchRemove: function () {
      var ids = this.sels.map(item => item.id)
      this.$confirm('确认删除选中记录吗？', '提示', {
        type: 'warning'
      }).then(() => {
        this.listLoading = true;
        //NProgress.start();
        let para = { ids: ids };
        this.$http.patch("/detail",ids)
        .then(Result=>{
          this.listLoading = false;
          this.getSystemdictionarydetails()
          if (Result.data.success){
            this.$message({
              message: Result.data.msg,
              type: 'success'
            })
          }
        })
        .catch(Result=>{
          this.$message({
            message: '网络走丢了',
            type: 'error'
          });
        })
      }).catch(() => {
      });
    }
  },

  mounted() {
    this.getSystemdictionarydetails();
    this.getType();

  }
}

</script>

<style scoped>

</style>
